#ifndef ARQ_H_
#define ARQ_H_

#include <stdint.h>

typedef uint8_t seq_nr_t;       /**< Frame Seq type */
typedef uint8_t frame_type_t;   /**< Frame type type */

/** Frame structure, not including FCS  */
typedef struct {
        frame_type_t type;      /* Frame type */
        seq_nr_t seq_nr;        /* Frame seq */
        uint8_t data[1];        /* Frame data */
}frame_t;

typedef struct {
        int frame_size;                 /* Maximum Frame Size */
        int timeout_msec;               /* Timeout between two bytes, ms */
        int retry;                      /* Frame Retry Times */
        seq_nr_t start;                 /* Current Frame Seq */
        int syn_req;                    /* require seq_nr to sync */
        frame_t * in;                   /* Buffer for Receiving */
        frame_t * out;                  /* Buffer for Sending */
        frame_t * acknak;               /* Buffer for ACK/NAK */
        int (*_put)(int ch);            /* Send Data: one byte */
        int (*_get)(int timeout);       /* Receive Data: one byte */
        uint8_t * temp;
}arq_t;

int arq_recv(arq_t * arq, uint8_t * buff, int bufflen, int timeout);
int arq_send(arq_t * arq, uint8_t * data, int datalen);

#define ARQ_CANCLE_RET                  -3

#endif /* ARQ_H_ */

